home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 1.iso
/
toolbox
/
src
/
exampleCode
/
opengl
/
cap
/
x_interfere.c
< prev
Wrap
C/C++ Source or Header
|
1996-11-11
|
7KB
|
238 lines
/*
* Copyright (C) 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/PushB.h>
#include "interfere.h"
/*
* For naming the widgets' resources.
*/
#define APP_NAME "interfere"
#define APP_CLASS "Interfere"
/*
* In case there's no app-defaults file.
*/
static String fallbacks[] =
{
"*canvasFrame.width: 500",
"*canvasFrame.height: 400",
"*canvasFrame.leftOffset: 20",
"*canvasFrame.topOffset: 40",
"*canvasFrame.rightOffset: 120",
"*canvasFrame.bottomOffset: 40",
"*Quit.rightOffset: 10",
"*Quit.bottomOffset: 10",
"*Animate.rightOffset: 10",
"*Animate.bottomOffset: 50",
"*Capping.rightOffset: 10",
"*Capping.bottomOffset: 90",
NULL,
};
enum {
NO_CAPPING = 0, INTERFERENCE_CHECKING
};
Boolean do_cap = False;
static void
interferenceCallback (Widget w, XtPointer client, XtPointer callback)
{
static unsigned int state = 0;
XmString string;
if (state == NO_CAPPING) {
state = INTERFERENCE_CHECKING;
string = XmStringCreateSimple("No Capping");
do_cap = True;
}
else {
state = NO_CAPPING;
string = XmStringCreateSimple("Capping");
do_cap = False;
}
XtVaSetValues(w, XmNlabelString, string, NULL);
XmStringFree(string);
drawScene ();
}
/*
* This is called until we press the 'Stop' button.
*/
static Boolean
animateWorkProc (XtPointer client_data)
{
drawScene ();
return False;
}
/*
* Used when the Animate/Stop button is pressed.
*/
static void
animateCallback (Widget w, XtPointer client, XtPointer callback)
{
static Boolean toggle = False;
static work_proc_id = 0;
XmString string;
XtAppContext app_context = (XtAppContext)client;
if (!toggle) {
Boolean animateWorkProc(XtPointer);
work_proc_id = XtAppAddWorkProc(app_context, animateWorkProc, NULL);
string = XmStringCreateSimple("Stop");
toggle = True;
}
else {
XtRemoveWorkProc(work_proc_id);
string = XmStringCreateSimple("Animate");
toggle = False;
}
XtVaSetValues(w, XmNlabelString, string, NULL);
XmStringFree(string);
}
/*
*
*/
static void
quitCallback (Widget w, XtPointer client, XtPointer callback)
{
exit(0);
}
/*
* Set up the application's desktop.
*/
Widget
setupDesktop (Widget parent, XtAppContext app_context)
{
Widget quit_button = XtVaCreateManagedWidget
("Quit", xmPushButtonWidgetClass, parent,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNtraversalOn, False,
NULL);
Widget animate_button = XtVaCreateManagedWidget
("Animate", xmPushButtonWidgetClass, parent,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNtraversalOn, False,
NULL);
Widget int_button = XtVaCreateManagedWidget
("Capping", xmPushButtonWidgetClass, parent,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNtraversalOn, False,
NULL);
Widget frame = XtVaCreateWidget("canvasFrame", xmFrameWidgetClass,
parent,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
XtAddCallback(animate_button, XmNactivateCallback, animateCallback,
app_context);
XtAddCallback(int_button, XmNactivateCallback, interferenceCallback, NULL);
XtAddCallback(quit_button, XmNactivateCallback, quitCallback, NULL);
return frame;
}
/* -------------------------------------------------------------- */
static
Boolean queryServer (Display * display)
{
int major_opcode = 0, first_event = 0, first_error = 0;
return XQueryExtension(display, "SGI-SUNDRY-NONSTANDARD",
&major_opcode, &first_event, &first_error);
}
int main (int argc, char ** argv)
{
XtAppContext app_context;
Widget toplevel = NULL;
Widget form = NULL, frame = NULL;
Display * display = NULL;
XVisualInfo * visual_info = NULL;
Colormap cmap;
int num_options = 0;
Arg args[0x20];
int num_args = 0;
XtToolkitInitialize();
app_context = XtCreateApplicationContext ();
XtAppSetFallbackResources(app_context, fallbacks);
display = XtOpenDisplay(app_context, NULL, APP_NAME, APP_CLASS,
NULL, 0, &argc, argv);
XtSetArg(args[num_args], XtNargc, argc); num_args++;
XtSetArg(args[num_args], XtNargv, argv); num_args++;
visual_info = getVisualInfo(display);
if (visual_info != NULL) {
cmap = XCreateColormap(display,
RootWindow(display, visual_info->screen),
visual_info->visual, AllocNone);
XtSetArg(args[num_args], XtNvisual, visual_info->visual); num_args++;
XtSetArg(args[num_args], XtNdepth, visual_info->depth); num_args++;
XtSetArg(args[num_args], XtNcolormap, cmap); num_args++;
}
toplevel = XtAppCreateShell(APP_NAME, APP_CLASS,
applicationShellWidgetClass,
display,
args, num_args);
if (queryServer(XtDisplay(toplevel)) == True) {
form = XtVaCreateWidget("form", xmFormWidgetClass, toplevel,
NULL);
/* Setup the desktop and return the widge that will be the
parent to the rendering area. The frame is unmanaged.
We take care of this inside initRenderingArea() */
frame = setupDesktop(form, app_context);
initRenderingArea(frame);
XtManageChild(form);
XtRealizeWidget(toplevel);
setCurrentRenderingContext(display);
XtAppMainLoop(app_context);
}
else {
fprintf(stderr, "You must run this on an SGI server\n");
return 1;
}
}